define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'coupon/couponuse/index',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'coupon_list',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'coupon_list.id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'coupon_number', title: __('Coupon'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), operate: 'LIKE'},
                        {field: 'status_title', title: __('Status'), formatter: Table.api.formatter.status, searchList: {"0": __('Not used'), "1": __('Used'), "2": __('Expired')}, custom: {"0":'success', "1":'danger', "2":'disabled'}},
                        {field: 'user_info', title: __('User info'), operate: 'LIKE',searchable:false},
                        {field: 'order_info', title: __('Order info'), operate: 'LIKE',searchable:false},
                        {field: 'coupon_info', title: __('Coupon info'), operate: 'LIKE',searchable:false},
                        {field: 'title_info', title: __('Coupon title'), operate: 'LIKE',searchable:false},
                        {field: 'start_time', title: __('Start time'), operate: 'LIKE',searchable:false},
                        {field: 'use_time', title: __('Use time'), operate: 'BETWEEN', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});